/**
package-info.java 
2017年9月20日下午3:31:05
@author
 */
/**
 * @author asus
 *
 */
package com.coder520.boot.hello.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.springframework.stereotype.Service;

import com.coder520.boot.hello.entity.User;

@Service
public class UserServiceImpl implements UserService{
	
	private List<User> list=new ArrayList<User>(Arrays.asList(
			new User("A","tony","tonyHome"),
			new User("B", "Alice", "AliceHome"),
			new User("C", "Ben", "BenHome")));
	@Override
	public List<User> getAllUser(){
		return list;
	}
	@Override
	public User getUserById(String id) {
		// TODO Auto-generated method stub
		User user=list.stream().filter(t -> t.getId().equals(id)).findFirst().get();
		return user;
	}
	@Override
	public void addUser(User user) {
		// TODO Auto-generated method stub
		list.add(user);
	}
	@Override
	public void updateUser(String id, User user) {
		// TODO Auto-generated method stub
		for(int i=0;i<list.size();i++) {
			User user2=list.get(i);
			if (user2.getId().equals(id)) {
				list.set(i, user);
				return;
			}
		}
	}
	@Override
	public void delUser(String id) {
		// TODO Auto-generated method stub
		list.removeIf(u -> u.getId().equals(id));
	}
}